import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import ElementPlus from "unplugin-element-plus/vite";
import path from 'path'
const pathSrc = path.resolve(__dirname, 'src')
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const envConfig = loadEnv(mode, "./");

  const ip = envConfig.VITE_API_BASEURL;
  return {
    plugins: [vue(), ElementPlus({})],
    base: process.env.NODE_ENV === "production" ? "./" : "/",
    resolve: {
			alias: { '@': pathSrc },
			extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
		},
    server: {
      // host: 'http://49.233.204.197:82',
      proxy: {
        "/auth": {
          target: ip,
          changeOrigin: true,
        },
        "/api": {
          target: ip,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
        "/biz": {
          target: ip,
          changeOrigin: true,
        },
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@import "./src/index.scss";`,
        },
      },
    },
  };
});
